import React, { Component } from 'react'
import TwsLayout from './tws-layout'
import { IntlProvider } from 'react-intl'
import locales from '../locales'
import '../less/index.less'
import asyncComponent from '../async-component'
import {
  HashRouter as Router,
  Route
} from 'react-router-dom'
import {getLangFromLocalStorage} from '../constant/lang-util'
import { LocaleProvider } from 'antd'
import { connect } from 'react-redux'
import QuizSuggestionBody from '../components/quiz-suggestions/quiz-suggestion-body'
const SingleChoiceQuizzesListBody = asyncComponent(()=>import('./single-choice-quizzes/single-choice-quizzes-list-body'))
const AddOrModifyMultipleChoiceQuizBody = asyncComponent(()=>import('./multiple-choice-quizzes/add-or-edit-multiple-choice-quiz-body'))
const MultipleChoiceQuizBody = asyncComponent(()=>import('./multiple-choice-quizzes/multiple-choice-quizzes-list'))
const AddOrEditSingleChoiceQuizBody = asyncComponent(()=>import('./single-choice-quizzes/add-or-edit-single-choice-quiz-body'))
const AddOrEditSubjectiveQuiz = asyncComponent(()=>import('./subjective-quizzes/add-or-edit-subjective-quiz-body'))
const AddOrEditBlankQuiz = asyncComponent(()=>import('./blank-quizzes/add-or-edit-blank-quiz-body'))
const CodingQuizzes = asyncComponent(()=>import('./coding-quizzes/coding-quizzes-list'))
const OnlineCodingQuizzes = asyncComponent(()=>import('./online-coding-quizzes/online-coding-quizzes-list'))
const OnlineLanguageQuizzes = asyncComponent(()=>import('./online-language-quizzes/online-language-quizzes-list'))
const BlankQuizzesList = asyncComponent(()=>import('./blank-quizzes/balnk-quizzes-list'))
const AddOrEditCodingQuiz = asyncComponent(()=>import('./coding-quizzes/add-or-edit-coding-quiz'))
const AddOrEditOnlineCodingQuiz = asyncComponent(()=>import('./online-coding-quizzes/add-or-edit-online-coding-quiz'))
const AddOrEditOnlineLanguageQuiz = asyncComponent(()=>import('./online-language-quizzes/add-or-edit-online-language-quiz'))
const SubjectiveQuizList = asyncComponent(()=>import('./subjective-quizzes/subjective-quizzes-list'))
const AddOrEditTags = asyncComponent(()=>import('./tags/add-or-edit-tags'))
const TagsList = asyncComponent(()=>import('./tags/tags-list'))
const LogicQuizzes = asyncComponent(()=>import('./logic-quizzes/logic-quizzes-list-body'))
const AddOrEditLogicQuizzes = asyncComponent(()=>import('./logic-quizzes/add-or-edit-logic-quiz-body'))
const StacksList = asyncComponent(()=>import('./stacks/stacks-list'))
const AddStack = asyncComponent(()=>import('./stacks/add-stack'))
const SimpleCodingQuizzesList = asyncComponent(()=>import('./simple-coding-quizzes/simple-coding-quizzes-list'))
const AddSimpleCodingQuiz = asyncComponent(()=>import('./simple-coding-quizzes/add-coding-quiz'))
const EditSimpleCodingQuiz = asyncComponent(()=>import('./simple-coding-quizzes/edit-coding-quiz'))

const SurveyQuizzesList = asyncComponent(()=>import('./survey-quizzes/survey-quizzes-list'))
const AddSurveyQuiz = asyncComponent(()=>import('./survey-quizzes/new-survey-quiz'))
const EditSurveyQuiz = asyncComponent(()=>import('./survey-quizzes/edit-survey-quiz'))


class App extends Component {
  render () {
    const lang = this.props.lang || getLangFromLocalStorage()
    const langData = locales[lang]
    return (<IntlProvider locale={langData.intlLocale} messages={langData.intlMessage}>
      <LocaleProvider locale={langData.locale}>
        <Router>
          <TwsLayout lang={lang}>
            <Route exact path='/' component={SubjectiveQuizList} />

            <Route exact path='/subjectiveQuizzes' component={SubjectiveQuizList} />
            <Route exact path='/subjectiveQuizzes/new' component={AddOrEditSubjectiveQuiz} />
            <Route exact path='/subjectiveQuizzes/:id/editor' component={AddOrEditSubjectiveQuiz} />

            <Route exact path='/singleChoiceQuizzes' component={SingleChoiceQuizzesListBody} />
            <Route exact path='/singleChoiceQuizzes/new' component={AddOrEditSingleChoiceQuizBody} />
            <Route exact path='/singleChoiceQuizzes/:id/editor' component={AddOrEditSingleChoiceQuizBody} />

            <Route exact path='/multipleChoiceQuizzes/:id/editor' component={AddOrModifyMultipleChoiceQuizBody} />
            <Route exact path='/multipleChoiceQuizzes/new' component={AddOrModifyMultipleChoiceQuizBody} />
            <Route exact path='/multipleChoiceQuizzes' component={MultipleChoiceQuizBody} />

            <Route exact path='/blankQuizzes' component={BlankQuizzesList} />
            <Route exact path='/blankQuizzes/new' component={AddOrEditBlankQuiz} />
            <Route exact path='/blankQuizzes/:id/editor' component={AddOrEditBlankQuiz} />
            <Route exact path='/codingQuizzes/' component={CodingQuizzes} />
            <Route exact path='/codingQuizzes/new' component={AddOrEditCodingQuiz} />
            <Route exact path='/codingQuizzes/:id/editor' component={AddOrEditCodingQuiz} />

            <Route exact path='/simpleCodingQuizzes/' component={SimpleCodingQuizzesList} />
            <Route exact path='/simpleCodingQuizzes/new' component={AddSimpleCodingQuiz} />
            <Route exact path='/simpleCodingQuizzes/:id/editor' component={EditSimpleCodingQuiz} />

            <Route exact path='/surveyQuizzes/' component={SurveyQuizzesList} />
            <Route exact path='/surveyQuizzes/new' component={AddSurveyQuiz} />
            <Route exact path='/surveyQuizzes/:id/editor' component={EditSurveyQuiz} />

            <Route exact path='/onlineCodingQuizzes/' component={OnlineCodingQuizzes} />
            <Route exact path='/onlineCodingQuizzes/new' component={AddOrEditOnlineCodingQuiz} />
            <Route exact path='/onlineCodingQuizzes/:id/editor' component={AddOrEditOnlineCodingQuiz} />
            <Route exact path='/onlineLanguageQuizzes/' component={OnlineLanguageQuizzes} />
            <Route exact path='/onlineLanguageQuizzes/new' component={AddOrEditOnlineLanguageQuiz} />
            <Route exact path='/onlineLanguageQuizzes/:id/editor' component={AddOrEditOnlineLanguageQuiz} />

            <Route exact path='/tags/new' component={AddOrEditTags} />
            <Route exact path='/tags/:id/editor' component={AddOrEditTags} />
            <Route exact path='/tags' component={TagsList} />
            <Route exact path='/logicQuizzes' component={LogicQuizzes} />
            <Route exact path='/logicQuizzes/new' component={AddOrEditLogicQuizzes} />
            <Route exact path='/logicQuizzes/:id/editor' component={AddOrEditLogicQuizzes} />
            <Route exact path='/stacks/new' component={AddStack} />
            <Route exact path='/stacks' component={StacksList} />
            <Route exact path='/suggestions' component={QuizSuggestionBody} />
          </TwsLayout>
        </Router>
      </LocaleProvider>
    </IntlProvider>)
  }
}

const mapStateToProps = ({lang}) => ({lang})

export default connect(mapStateToProps)(App)
